package xiao_jin.fantasy.client.renderer.entity;

import com.google.common.collect.Sets;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.render.entity.model.AllayEntityModel;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.util.Identifier;
import xiao_jin.fantasy.client.renderer.entity.model.StrangeSquidEntityModel;
import xiao_jin.fantasy.client.renderer.entity.state.StrangeSquidEntityRenderState;
import xiao_jin.fantasy.core.common.entity.entityType.mob.StrangeSquidEntity;

import java.util.Set;

import static xiao_jin.fantasy.Fantasy.MOD_ID;

@Environment(EnvType.CLIENT)
public class StrangeSquidEntityRenderer extends MobEntityRenderer<StrangeSquidEntity, StrangeSquidEntityRenderState, StrangeSquidEntityModel> {
    private static final Set<EntityModelLayer> LAYERS = Sets.newHashSet();
    public static final EntityModelLayer STRANGE_SQUID = registerMain("boat/acacia");

    public StrangeSquidEntityRenderer(EntityRendererFactory.Context context) {
        super(context, new StrangeSquidEntityModel(context.getPart(StrangeSquidEntityRenderer.STRANGE_SQUID)), 0.4F);
    }

    private static final Identifier TEXTURE = Identifier.of(MOD_ID,"textures/entity/strange_squid.png");

    public StrangeSquidEntityRenderState createRenderState() {
        return new StrangeSquidEntityRenderState();
    }

    @Override
    public Identifier getTexture(StrangeSquidEntityRenderState state) {
        return TEXTURE;
    }
    private static EntityModelLayer registerMain(String id) {
        return register(id, "main");
    }
    private static EntityModelLayer register(String id, String layer) {
        EntityModelLayer entityModelLayer = create(id, layer);
        if (!LAYERS.add(entityModelLayer)) {
            throw new IllegalStateException("Duplicate registration for " + entityModelLayer);
        } else {
            return entityModelLayer;
        }
    }
    private static EntityModelLayer create(String id, String layer) {
        return new EntityModelLayer(Identifier.ofVanilla(id), layer);
    }
}
